package net.cyan.commons.log;

import net.cyan.commons.util.ExceptionUtils;

/**
 * 
 * @author camel
 * @date 2008-12-10
 */
public abstract class AbstractLog implements Log
{
    private Printable warnPrintable;

    private Printable errorPrintable;

    private Printable fatalPrintable;

    public AbstractLog()
    {
    }

    public synchronized Printable getWarnPrintable()
    {
        if (warnPrintable == null)
            warnPrintable = new LogPrintable(this, LogLevel.warn);
        return warnPrintable;
    }

    public synchronized Printable getErrorPrintable()
    {
        if (errorPrintable == null)
            errorPrintable = new LogPrintable(this, LogLevel.error);
        return errorPrintable;
    }

    public synchronized Printable getFatalPrintable()
    {
        if (fatalPrintable == null)
            fatalPrintable = new LogPrintable(this, LogLevel.fatal);
        return fatalPrintable;
    }

    public void warn(Throwable th)
    {
        ExceptionUtils.logThrowable(th, getWarnPrintable(), null);
    }

    public void warn(String s, StackTraceElement[] traces)
    {
        warn(s);
        ExceptionUtils.logStackTrace(traces, getWarnPrintable(), null);
    }

    public void warn(String s, Throwable th)
    {
        warn(s);
        ExceptionUtils.logThrowable(th, getWarnPrintable(), null);
    }

    public void error(Throwable th)
    {
        ExceptionUtils.logThrowable(th, getErrorPrintable(), null);
    }

    public void error(String s, StackTraceElement[] traces)
    {
        error(s);
        ExceptionUtils.logStackTrace(traces, getErrorPrintable(), null);
    }

    public void error(String s, Throwable th)
    {
        error(s);
        ExceptionUtils.logThrowable(th, getErrorPrintable(), null);
    }

    public void fatal(Throwable th)
    {
        ExceptionUtils.logThrowable(th, getFatalPrintable(), null);
    }

    public void fatal(String s, StackTraceElement[] traces)
    {
        fatal(s);
        ExceptionUtils.logStackTrace(traces, getFatalPrintable(), null);
    }

    public void fatal(String s, Throwable th)
    {
        fatal(s);
        ExceptionUtils.logThrowable(th, getFatalPrintable(), null);
    }
}
